<?php
    $form = $this->beginWidget('CActiveForm', array(
    'action' => $this->createUrl('update'),
    'method' => 'POST',
    'id' => 'myForm',
    'htmlOptions'=>array('target'=>'ajax-frame')
    ));
?>
<table>
    <tbody>
        <tr>
            <td width="127" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>学年：</td>
            <td width="456" class="pt20">
                <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                    <span class="fl select_shelter select_shelter2">
                        <select class="fl fontc_666" name="info[exam_term_id]">
                            <?php if (!empty($info['eduTermData'])): ?>
                                <?php foreach ($info['eduTermData'] as $ev): ?>
                                    <option value="<?php echo $ev['term_start_year']; ?>~<?php echo $ev['term_end_year']; ?>" <?php if ($data['exam_term_id'] == $ev['term_start_year'] . '~' . $ev['term_end_year']) echo 'selected'; ?>>
                                        <?php echo $ev['term_start_year']; ?>~<?php echo $ev['term_end_year']; ?>
                                    </option>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </select>
                    </span>
                </span>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>学期：</td>
            <td valign="top" class="pt20">
                <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                    <span class="fl select_shelter select_shelter2">
                        <select class="fl fontc_666" name="info[exam_term_sx]" id="exam_term_sx">
                            <option value="">请选择</option>
                            <option value="s" <?php if ($data['exam_term_sx'] == 's') echo 'selected'; ?> >第一学期</option>
                            <option value='x' <?php if ($data['exam_term_sx'] == 'x') echo 'selected'; ?> >第二学期</option>
                        </select>
                    </span>
                </span>
                <div class="fl pt7 pl10">
                    <p id="exam_term_sxTip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>考试日期：</td>
            <td valign="top" class="pt20">
                <input type="text" name="info[exam_start_time]" class="fl w140 pt5 pr5 pb5 pl10 height20 border_c border_3 fontc_666 SipeiTime" value="<?php echo date('Y-m-d', $data['exam_start_time']); ?>" id="start_time"  onfocus="var d5222 = $dp.$('end_time');
                        WdatePicker({dateFmt: 'yyyy-MM-dd', onpicked: function() {
                                d5222.focus();
                            }, maxDate: '#F{$dp.$D(\'end_time\')}'})" />
                <span class="fl pr5 pl5">至</span>
                <input type="text" name="info[exam_end_time]" class="fl w140 pt5 pr5 pb5 pl10 height20 border_c border_3 fontc_666 SipeiTime" value="<?php echo date('Y-m-d', $data['exam_end_time']); ?>" id="end_time" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'start_time\')}'})" />
                <div class="fl pt7 pl10">
                    <p id="start_timeTip" ></p>
                     <p id="end_timeTip" ></p>
                </div>
            </td>
        </tr>
        <tr> 
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>学段：</td>
            <td valign="top" class="pt20">
                <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                    <span class="fl select_shelter select_shelter2">
                        <select class="fl fontc_666" onchange="getGrade(this.value)" name="info[exam_edu_type]" id="exam_edu_type">
                            <option value="0">请选择</option>
                            <?php if (!empty($info['xdDatas'])): ?>
                                <?php foreach ($info['xdDatas'] as $xv): ?>
                                    <option value="<?php echo $xv['edu_id']; ?>" <?php if ($data['exam_edu_type'] == $xv['edu_id']) echo 'selected'; ?> >
                                        <?php echo $xv['edu_name']; ?>  
                                    </option>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </select>
                    </span>
                </span>
                <div class="fl pt7 pl10">
                    <p id="exam_edu_typeTip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>参加年级：</td>
            <td valign="top" class="pt20">
                <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                    <span class="fl select_shelter select_shelter2" id="gradeSelect">
                        <select class="fl fontc_666" name="info[exam_edu_grade]" id="exam_edu_grade">
                            <option value="">请选择</option>
                        </select>
                    </span>
                </span>
                <div class="fl pt7 pl10">
                    <p id="exam_edu_gradeTip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>项目名称：</td>
            <td valign="top" class="pt20">
                <input type="text" name="info[exam_name]" value="<?php echo $data['exam_name']; ?>"   class="fl w100 pt5 pr5 pb5 pl5 height20 border_c border_3 fontc_666" id="exam_name" >
                <div class="fl pt7 pl10">
                    <p id="exam_nameTip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>考试号位数：</td>
            <td valign="top" class="pt20"><input type="text" name="info[exam_num]" value="<?php echo $data['exam_num']; ?>" id="exam_num" class="fl w100 pt5 pr5 pb5 pl5 height20 border_c border_3 fontc_666" />
                <div class="fl pt7 pl10">
                    <p id="exam_numTip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt20 pr3"><span class="pr5 fontc_orange_red">*</span>状态：</td>
            <td valign="top" class="pt20">
                <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                    <span class="fl select_shelter select_shelter2">
                        <select class="fl fontc_666" name="info[exam_status]">
                            <option value="1" <?php if ($data['exam_status'] == '1') echo 'selected'; ?>>上传数据</option>
                            <option value="2" <?php if ($data['exam_status'] == '2') echo 'selected'; ?>>阅卷</option>
                            <option value="0" <?php if ($data['exam_status'] == '0') echo 'selected'; ?>>归档</option>
                        </select>
                    </span>
                </span>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt15 pr3 height20"><span class="pr5 fontc_orange_red">*</span>参加学校：</td>
            <td valign="top" class="pt15">
                <ul class="clearfix OutList"  id="checkSchool">
                    <li  class='fl pr12 pb5'>
                        <h1>请选择学段</h1>
                    </li>

                   
                    
                </ul>
				 <?php if (!empty($data['school_ids'])):?>
                    <?php foreach ($data['school_ids'] as $ck=>$cv):?>
                        <input type="hidden" name="school_checked[]" value="<?php echo $cv?>">
                    <?php endforeach;?>
                    <?php endif;?>
                <div class="formValidator_tip">
                    <p id="test33Tip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <td valign="top" align="right" class="pt15 pr3 height20"><span class="pr5 fontc_orange_red">*</span>参加科目：</td>
            <td valign="top" class="pt15">
                <ul id="checkboxSubject" class="clearfix OutList">
                    <?php if (!empty($info['subjectDatas'])): ?>
                        <?php foreach ($info['subjectDatas'] as $suv): ?>
                            <li class="fl pr12 pb5">
                                <input type="checkbox"  name="subject[]" value="<?php echo $suv['subject_code']; ?>" <?php if (in_array($suv['subject_code'], $data['exam_subject_ids'])) echo 'checked'; ?> />
                                <span class="pl5"> <?php echo $suv['subject_name']; ?></span>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </ul>
                <div class="clearfix formValidator_tip">
                    <p id="test2Tip" ></p>
                </div>
            </td>
        </tr>
        <tr>
            <input type="hidden" name="info[exam_id]" value="<?php echo $data['exam_id']; ?>">
            <td colspan="2" align="center" class="pt20 pb20">
                <input type="submit" name="submit"  onclick="return submitCheck()" value="保存" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            </td>
        </tr>
    </tbody>
</table>
<?php
$this->endWidget();
?>  
<iframe src='' style="display:none" name='ajax-frame'></iframe>
<script type="text/javascript">
function submitCheck(){

	var is_checked = true;
	if($.trim($("#checkboxSubject").html()) == ''){
		$("#test2Tip").html('<p class="noticeWrap"><b class="ico-warning"></b><span class="txt-err">请更新科目信息</span></p>');
		is_checked = false;
	}else{
		var bb = '';
		$("input[name='subject[]']:checkbox:checked").each(function(){
			bb+=$(this).val()+',';
		});
		if(bb == ''){

			$("#test2Tip").html('<p class="noticeWrap"><b class="ico-warning"></b><span class="txt-err">至少选择1个</span></p>');
			is_checked = false;
		}else{
			$("#test2Tip").html('<p class="noticeWrap"><b class="ico-succ"></b><span class="txt-succ">已选择</span></p>');
			is_checked = true;
		}
	}

	if($.trim($("#checkSchool").html()) == "<h1>请选择学段</h1>"){
		is_checked = false;
	}else{
		var aa = '';
		$("input[name='school[]']:checkbox:checked").each(function(){
			aa+=$(this).val()+',';
		});
		if(aa == ''){

			$("#test33Tip").html('<p class="noticeWrap"><b class="ico-warning"></b><span class="txt-err">至少选择1个</span></p>');
			is_checked = false;
		}else{
			$("#test33Tip").html('<p class="noticeWrap"><b class="ico-succ"></b><span class="txt-succ">已选择</span></p>');
			is_checked = true;
		}
	}
	return is_checked;
}

function getGrade(edu_id, grade_id, exam_id) {
	$.getJSON("<?php echo $this->createUrl("get_grade"); ?>", {edu_id: edu_id, grade_id: grade_id, exam_id: exam_id}, function(result) {
		
		$("#exam_edu_grade").html(result.grade);
		$("#checkSchool").html(result.school);
		if( $("#checkSchool input").length < 1 ){
			$("#checkSchool").parent().next().hide();
		}else{
			$("#checkSchool").parent().next().show();
		}
		xuanzhong();
	});
}

getGrade(<?php echo $data['exam_edu_type'] . "," . $data['exam_edu_grade'] . "," . $data['exam_id']; ?>);

function xuanzhong(){
	$("input[name='school_checked[]']:hidden").each(function(){
		var checkeds = $(this).val();
		$("input[name='school[]']:checkbox").each(function(){
			if(checkeds == $(this).val()){
				$(this).attr("checked", true)
			}
		});
	})

}

$(function() {
	if( $("#checkSchool input").length < 1 ){
		$("#checkSchool").parent().next().hide();
	}else{
		$("#checkSchool").parent().next().show();
	}
	function testTime(){
		var msg="";
		if( $("#start_time").val() == "" ){
			msg = "请选择考试开始时间";
		}else if( $("#end_time").val() == "" ){
			msg = "请选择考试结束时间";
		}else{
			msg = true;
		}

		return msg;
	}
	$.formValidator.initConfig({formID: "myForm", theme: "126", submitOnce: false,
	onError: function(msg, obj, errorlist) {
		$("#errorlist").empty();
		$.map(errorlist, function(msg) {
			$("#errorlist").append("<li>" + msg + "</li>")
		});
	}
	});
	/*学期验证*/
	$("#exam_term_sx").formValidator({
		onShowText: "",
		onShow: "",
		onFocus: "",
		onCorrect: "已选择"
	}).inputValidator({
		min: 1,
		onError: "请选择学期"
	});
	/*学期验证*/
	$("#end_time").formValidator({
		tipID:"start_timeTip",
		onShowText: "",
		onShow: "",
		onFocus: "",
		onCorrect: ""
	}).inputValidator({
		min: 1,
		onError: "请选择考试结束日期"
	}).functionValidator({
		fun:testTime
	});
	/*学期验证*/
	$("#exam_term_sx").formValidator({
		onShowText: "",
		onShow: "",
		onFocus: "",
		onCorrect: "已选择"
	}).inputValidator({
		min: 1,
		onError: "请选择学期"
	}).functionValidator({
		fun:testTime
	});
	/*学段验证*/
	$("#exam_edu_type").formValidator({
		onShowText: "",
		onShow: "",
		onFocus: "",
		onCorrect: "已选择"
	}).inputValidator({
		min: 1,
		onError: "请选择学段"
	});
	/*参加年级验证*/
	$("#exam_edu_grade").formValidator({
		onShowText: "",
		onShow: "",
		onFocus: "",
		onCorrect: "已选择"
	}).inputValidator({
		min: 1,
		onError: "请选择参加年级"
	});
	/*名称验证*/
	$("#exam_name").formValidator({
		onShowText: "请输入项目名称",
		onShow: "",
		onFocus: "",
		onCorrect: "输入正确",
		leftTrim:true,
		rightTrim:true
	}).inputValidator({
		min: 1,
		max:100,
		onError: "项目名称长度在1-100之间(1-50个汉字)"
	});

	/*考试号位数验证*/
	$("#exam_num").formValidator({
		onShowText: "请输入考号位数",
		onShow: "",
		onFocus: "",
		onCorrect: "输入正确",
		leftTrim:true,
		rightTrim:true
	}).inputValidator({
		min: 1,
		max:3,
		onError: "考试号位数长度在1-3之间"
	}).regexValidator({
		regExp: "intege1",
		dataType: "enum",
		onError: "考号位数必须是正整数"
	});



})
</script>
<?php exit;?>